package com.gonsin.gview.model.dynamic.form;

import com.gonsin.gview.model.GFormItemModel;
import com.gonsin.gview.model.data.GTreeDataModel;
import com.gonsin.gview.model.dynamic.data.DynamicTreeData;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@ApiModel("树状下拉框")
@AllArgsConstructor
@NoArgsConstructor
public class DynamicTreeSelector extends DynamicFormItem {

    @ApiModelProperty("selector表示下拉框，还有check_box\\file\\radio\\rich_text\\text_input\\tree_check_box\\tree_selector")
    private final String itemType = "tree_selector";

    @ApiModelProperty("是否必选")
    private boolean required = true;

    @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
    private String keyName;

    @ApiModelProperty("显示的名字")
    private String name;

    @ApiModelProperty("根据情况显示")
    private String showIf = "1";

    @ApiModelProperty("根据情况禁用")
    private String disableIf = "0";

//    @Deprecated
//    @ApiModelProperty("下拉的内容")
//    private List<KeyValue> values;

    @ApiModelProperty("数据获取相关")
    private DynamicTreeData treeData;

    @ApiModelProperty("当单个表单项被修改时，触发对应的action事件")
    private String onChangeAction;

    public static DynamicTreeSelectorBuilder builder() {
        return new DynamicTreeSelectorBuilder();
    }


    public static final class DynamicTreeSelectorBuilder {
        @ApiModelProperty("是否必选")
        private boolean required = true;

        @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
        private String keyName;

        @ApiModelProperty("显示的名字")
        private String name;

        @ApiModelProperty("根据情况显示")
        private String showIf = "1";

        @ApiModelProperty("根据情况禁用")
        private String disableIf = "0";

//    @Deprecated
//    @ApiModelProperty("下拉的内容")
//    private List<KeyValue> values;

        @ApiModelProperty("数据获取相关")
        private DynamicTreeData treeData;

        @ApiModelProperty("当单个表单项被修改时，触发对应的action事件")
        private String onChangeAction;

        private DynamicTreeSelectorBuilder() {
        }

        public DynamicTreeSelectorBuilder required(boolean required) {
            this.required = required;
            return this;
        }

        public DynamicTreeSelectorBuilder keyName(String keyName) {
            this.keyName = keyName;
            return this;
        }

        public DynamicTreeSelectorBuilder name(String name) {
            this.name = name;
            return this;
        }

        public DynamicTreeSelectorBuilder showIf(String showIf) {
            this.showIf = showIf;
            return this;
        }

        public DynamicTreeSelectorBuilder disableIf(String disableIf) {
            this.disableIf = disableIf;
            return this;
        }

        public DynamicTreeSelectorBuilder treeData(DynamicTreeData treeData) {
            this.treeData = treeData;
            return this;
        }

        public DynamicTreeSelectorBuilder onChangeAction(String onChangeAction) {
            this.onChangeAction = onChangeAction;
            return this;
        }

        public DynamicTreeSelector build() {
            DynamicTreeSelector dynamicTreeSelector = new DynamicTreeSelector();
            dynamicTreeSelector.setRequired(required);
            dynamicTreeSelector.setKeyName(keyName);
            dynamicTreeSelector.setName(name);
            dynamicTreeSelector.setShowIf(showIf);
            dynamicTreeSelector.setDisableIf(disableIf);
            dynamicTreeSelector.setTreeData(treeData);
            dynamicTreeSelector.setOnChangeAction(onChangeAction);
            return dynamicTreeSelector;
        }
    }
}
